using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;


using Material.Object;
using Material.DAL;
namespace Material.Entity
{
	public class TblKelompokEntity
	{
		private Accessor accessor;
		private string connString;

		public TblKelompokEntity (string _connString)
		{
			 this.connString = _connString;
		}

		public int Insert(TblKelompok tblkelompok)
		{
			 int result = -1;
			 accessor = new Accessor(true, connString);
			 accessor.CommandText = "TblKelompok_Insert";
			 accessor.CommandType = CommandType.StoredProcedure;
			 accessor.Add("@Id" ,tblkelompok.Id );
			 accessor.Add("@Kelompok" ,tblkelompok.Kelompok );
			 accessor.Add("@Keterangan" ,tblkelompok.Keterangan );
			 accessor.Add("@CreatedDate" ,tblkelompok.CreatedDate );
			 accessor.Add("@CreatedBy" ,tblkelompok.CreatedBy );
			 accessor.Add("@ModifiedDate" ,tblkelompok.ModifiedDate );
			 accessor.Add("@ModifiedBy" ,tblkelompok.ModifiedBy );

			 result = Excutor.ExecuteNonQuery(accessor);
			 if (result != -1)
				 accessor.CommitTransaction();
			 else
				 accessor.RollBackTransaction();
			 return result;
		}

		public int Update(TblKelompok tblkelompok)
		{
			 int result = -1;
			 accessor = new Accessor(true, connString);
			 accessor.CommandText = "TblKelompok_Update";
			 accessor.CommandType = CommandType.StoredProcedure;
			 accessor.Add(@"Id" ,tblkelompok.Id );
			 accessor.Add(@"Kelompok" ,tblkelompok.Kelompok );
			 accessor.Add(@"Keterangan" ,tblkelompok.Keterangan );
			 accessor.Add(@"CreatedDate" ,tblkelompok.CreatedDate );
			 accessor.Add(@"CreatedBy" ,tblkelompok.CreatedBy );
			 accessor.Add(@"ModifiedDate" ,tblkelompok.ModifiedDate );
			 accessor.Add(@"ModifiedBy" ,tblkelompok.ModifiedBy );

			 result = Excutor.ExecuteNonQuery(accessor);
			 if (result != -1)
				 accessor.CommitTransaction();
			 else
				 accessor.RollBackTransaction();
			 return result;
		}

		public int Delete(TblKelompok tblkelompok)
		{
			 int result = -1;
			 accessor = new Accessor(true, connString);
			 accessor.CommandText = "TblKelompok_Delete";
			 accessor.CommandType = CommandType.StoredProcedure;
			 accessor.Add(@"Id" ,tblkelompok.Id);

			 result = Excutor.ExecuteNonQuery(accessor);
			 if (result != -1)
				 accessor.CommitTransaction();
			 else
				 accessor.RollBackTransaction();
			 return result;
		}

		public TblKelompok GetDataByID(TblKelompok tblkelompok)
		{
			 TblKelompok result = new TblKelompok();
			 accessor = new Accessor(true, connString);
			 accessor.CommandText = "TblKelompok_SelectByID";
			 accessor.CommandType = CommandType.StoredProcedure;
			 accessor.Add(@"Id" ,tblkelompok.Id);

			 SqlDataReader rdr = Excutor.GetDataReader(accessor);
			 if (rdr.HasRows)
			 {
				 while (rdr.Read())
					 {
						 result.Id = rdr.GetInt16(0);
						 result.Kelompok = rdr.GetString(1);
						 result.Keterangan = rdr.GetString(2);
						 result.CreatedDate = rdr.GetDateTime(3);
						 result.CreatedBy = rdr.GetString(4);
						 result.ModifiedDate = rdr.GetDateTime(5);
						 result.ModifiedBy = rdr.GetString(6);
					  }
			}
			 return result;
		}

		public List<TblKelompok> GetDataAll(TblKelompok tblkelompok)
		{
			 List<TblKelompok> result = new List<TblKelompok>();
			 accessor = new Accessor(true, connString);
			 accessor.CommandText = "TblKelompok_SelectAll";
			 accessor.CommandType = CommandType.StoredProcedure;

			 SqlDataReader rdr = Excutor.GetDataReader(accessor);
			 if (rdr.HasRows)
			 {
				 while (rdr.Read())
					 {
						 TblKelompok obj = new TblKelompok();
						 obj.Id = rdr.GetInt16(0);
						 obj.Kelompok = rdr.GetString(1);
						 obj.Keterangan = rdr.GetString(2);
						 obj.CreatedDate = rdr.GetDateTime(3);
						 obj.CreatedBy = rdr.GetString(4);
						 obj.ModifiedDate = rdr.GetDateTime(5);
						 obj.ModifiedBy = rdr.GetString(6);
						 result.Add(obj);
					  }
			}
			 return result;
		}

	}
}
